Hệ thống quản lý trường học bằng PHP / MySQLi

1 <?php
2  include(
'connect.php');
3  error_reporting(
0);//turning off error reporting
4  
if(isset($_POST["Importstudent"])){
5         
6         $filename=$_FILES[
"file"]["tmp_name"];
7  
8  
9          
if($_FILES["file"]["size"] > 0)
10          {
11             $file = fopen($filename,
"r");
12             
while (($getData = fgetcsv($file, 10000, ",")) !== FALSE)
13              {
14  
15
16                $sql =
"INSERT into marks(admission_number, course_id, term, year, exam_series, maths, english, kiswahili, social_studies, science, average)
17                    values ('"
.$getData[0]."','".$getData[1]."','".$getData[2]."','".$getData[3]."','".$getData[4]."','".$getData[5]."','".$getData[6]."','".$getData[7]."','".$getData[8]."','".$getData[9]."','".$getData[10]."')";
18                    $result = mysqli_query($db, $sql);
19                 
if(!isset($result))
20                 {
21                     echo
"<script type=\"text/javascript\">
22                             alert(\"Invalid File:Please Upload CSV File.\");
23                             window.location = \"markstep6.php\"
24                           </script>"
;
25                 }
26                 
else {
27                       echo
"<script type=\"text/javascript\">
28                         alert(\"CSV File has been successfully Imported.\");
29                         window.location = \"markstep6.php\"
30                     </script>"
;
31                 }
32              }
33             
34              fclose($file);
35          }
36     }
37 ?>
38
39 <?php
40  
41  
if(isset($_POST["Exportstudent"])){
42          
43       header(
'Content-Type: text/csv; charset=utf-8');
44       header(
'Content-Disposition: attachment; filename=data.csv');
45       $output = fopen(
"php://output", "w");
46       fputcsv($output, array(
'Student ID', 'Course ID', 'Term', 'Year', 'Exam_Series','Maths', 'English', 'Kiswahili', 'Chemistry', 'Physics/Biology','Average'));
47       $query =
"SELECT * from marks ORDER BY average DESC";
48       $result = mysqli_query($db, $query);
49       
while($row = mysqli_fetch_assoc($result))
50       {
51            fputcsv($output, $row);
52       }
53       fclose($output);
54  }
55  
56 ?>
57
58  


Gõ tìm kiếm nhanh...